package com.lxh.lxhcrm.model.service;

import com.lxh.lxhcrm.model.dao.afterSale.*;
import com.lxh.lxhcrm.model.mappers.afterSale.ComplaintMapper;
import com.lxh.lxhcrm.model.mappers.afterSale.CustomerCareMapper;
import com.lxh.lxhcrm.model.mappers.afterSale.CustomerServiceMapper;
import com.lxh.lxhcrm.model.mappers.afterSale.KnowLedgeMapper;
import com.lxh.lxhcrm.model.pojos.*;
import com.lxh.lxhcrm.model.pojos.ServeRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 开发团队 ：lxh
 * 开发人员 ：李兴洋
 * 开发时间 ：2020年3月25日14:13:27
 * 类的名称 ：AfterSaleService
 * 类的描述 ：客户服务、关怀、投诉
 */

@Service
public class AfterSaleService {
    @Autowired
    KnowLedgeMapper km;
    @Autowired
    KnowledgeDao knowledgeDao;
    @Autowired
    KnowledgeClassifyDao knowledgeClassifyDao;

    @Autowired
    ComplaintMapper complaintMapper;
    @Autowired
    ComplaintDao complaintDao;

    @Autowired
    CustomerCareMapper customerCareMapper;
    @Autowired
    CareRecordDao careRecordDao;
    @Autowired
    CareTypeDao careTypeDao;

    @Autowired
    CustomerServiceMapper customerServiceMapper;
    @Autowired
    CustomerServiceDao customerServiceDao;
    @Autowired
    ServeTypeDao serveTypeDao;

//    知识库页面功能
    //所有文章
    public List<Knowledge> findAllKnowledge(String search,String kcName,String orderByChose){
        return km.findAllKnowledge(search,kcName,orderByChose);
    }

    //所有文章分类
    public List<KnowledgeClassify> findAllKnowledgeClassify(){ return km.findAllKnowledgeClassify(); }

    //添加知识库文章
    public void addKnowledge(Knowledge knowledge) {
        Date now = new Date();
        knowledge.setReleaseTime(now);
        knowledgeDao.save(knowledge);
    }

    //删除知识库文章
    public void deleteK(Integer k){knowledgeDao.deleteById(k);}

    //添加知识库文章分类
    public void addKnowledgeClassify (KnowledgeClassify kc){
        knowledgeClassifyDao.save(kc);
    }

    //删除知识库分类
    public void deleteKc(Integer kcNo) {
        knowledgeClassifyDao.deleteById(kcNo);
    }

    //知识库审批
    public void knowledgeCheck(Integer essId){
        km.updateCheck(essId);
    }

//客户投诉部分功能

    //所有投诉
    public List<Complaint> findAllComplaint(String search,String kcName){
        return complaintMapper.findAllComplaint(search,kcName);
    }

    //添加投诉
    public void addComplaint(Complaint c){
        Date now = new Date();
        c.setComTime(now);
        complaintDao.save(c);
    }
    //删除投诉
    public void deleteComplaint(Integer cNo){ complaintDao.deleteById(cNo);}
    //投诉审批
    public void complaintCheck(Integer comId){
        complaintMapper.updateCheck(comId);
    }

//客户关怀部分功能
    //所有关怀信息查询
    public List<CareRecord> findAllCustomerCare(String search,String kcName){
        return customerCareMapper.findAllCustomerCare(search,kcName);
    }
    //添加关怀信息
    public void  addCareRecord(CareRecord cr){
        Date now = new Date();
        cr.setBeginTime(now);
        careRecordDao.save(cr);
    }
    //删除关怀记录
    public void deleteCareRecord(Integer crNo){ careRecordDao.deleteById(crNo);}
    //关怀审批
    public void careCheck(Integer careId){
        customerCareMapper.updateCheck(careId);
    }
    //所有关怀类型
    public List<CareType> allCareType(){
        return customerCareMapper.findCareType();
    }
    //新增关怀类型
    public void addCareType(CareType ct){
        careTypeDao.save(ct);
    }
    //删除关怀类型
    public void deleteCareTypeById(Integer ctId){
        careTypeDao.deleteById(ctId);
    }

//客户服务部分功能
    //所有客户服务信息查询
    public List<ServeRecord> findAllCusService(String search,String kcName){ return customerServiceMapper.findAllCusServic(search,kcName);}
    //添加客户服务信息
    public void addCusService(ServeRecord cs){
        Date now = new Date();
        cs.setBeginTime(now);
        customerServiceDao.save(cs);
    }
    //删除服务记录
    public void deleteServeRecord(Integer srNo){ customerServiceDao.deleteById(srNo);}
    //服务审批
    public void serveCheck(Integer serveId){
        customerServiceMapper.updateCheck(serveId);
    }
    //服务类型集合
    public List<ServeType> findAllServeType(){
        return customerServiceMapper.findAllServeType();
    }
    //服务类型新增
    public void addServeType(ServeType serveType){
        serveTypeDao.save(serveType);
    }
    //服务类型删除
    public void deleteServeType(Integer stId){
        serveTypeDao.deleteById(stId);
    }
}
